// 1. 创建备忘录对象
type Memento = {
    state: string;
  };
  
  // 2. 创建发起人对象
  class Originator {
    state: string;
  
    constructor(state: string) {
      this.state = state;
    }
  
    // 创建备忘录
    createMemento(): Memento {
      return {
        state: this.state,
      };
    }
  
    // 恢复备忘录
    restoreMemento(memento: Memento) {
      this.state = memento.state;
    }
  }
  
  // 3. 创建管理者对象
  class Caretaker {
    memento: Memento;
  
    setMemento(memento: Memento) {
      this.memento = memento;
    }
  
    getMemento() {
      return this.memento;
    }
  }
  
  const originator = new Originator("123");
  const caretaker = new Caretaker();
  caretaker.setMemento(originator.createMemento());
  originator.state = "456";
  console.log(originator.state);
  originator.restoreMemento(caretaker.getMemento());
  console.log(originator.state);